public class Solution1629 {
    public char slowestKey(int[] releaseTimes, String keysPressed) {
        char[] chars=keysPressed.toCharArray();
        int n=chars.length;
        int[] count=new int[26];
        count[chars[0]-'a']=releaseTimes[0];
        for (int i=1;i<n;i++){
            count[chars[i]-'a']=Math.max(count[chars[i]-'a'],releaseTimes[i]-releaseTimes[i-1]);
        }
        int max=0;
        char ans=' ';
        for (int i=25;i>=0;i--){
            if (count[i]>max){
                max=count[i];
                ans=(char)(i+'a');
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1629().slowestKey(new int[]{9,29,49,50},"cbcd"));
    }
}
